package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.WithdrawableBean
import com.haoshuang.zhouzhoubang.model.bean.WithdrawalDetailsBean
import com.haoshuang.zhouzhoubang.model.bean.YeBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class BalanceWithdrawalViewModel : BaseViewModel() {

    /**
     * 获取可提现列表
     */
    val getNotWithdrawListData = StatefulMutableLiveData<WithdrawableBean>()
    fun getNotWithdrawList(p: Int) = netRequest {
        start { getNotWithdrawListData.value = StateData.Loading }
        request { ApiRepo.getNotWithdrawList(p) }
        success { getNotWithdrawListData.value = StateData.Success(it.data) }
        error { code, msg ->
            getNotWithdrawListData.value = StateData.Error(code, msg)
        }
    }

    val getData = StatefulMutableLiveData<WithdrawalDetailsBean>()
    fun getData(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<WithdrawalDetailsBean>("/api/wallet/masterSaveWithdraw", *params,
                onStart = {
                    getData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData.value = StateData.Success(it)
                })
        }
    }

    val getData4 = StatefulMutableLiveData<Any>()
    fun getData4(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/wallet/cancel_bind_openid", *params,
                onStart = {
                    getData4.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData4.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData4.value = StateData.Success(it)
                })
        }
    }

    /**
     * 支付宝解绑
     */
    val cancelBindAlipay = StatefulMutableLiveData<Any>()
    fun cancelBindAlipay(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/wallet/cancel_bind_alipay", *params,
                onStart = {
                    cancelBindAlipay.value = StateData.Loading
                },
                onError = { code, msg ->
                    cancelBindAlipay.value = StateData.Error(code, msg)
                }, onSuccess = {
                    cancelBindAlipay.value = StateData.Success(it)
                })
        }
    }

    val getData3 = StatefulMutableLiveData<Any>()
    fun getData3(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/wallet/bind_openid", *params,
                onStart = {
                    getData3.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData3.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData3.value = StateData.Success(it)
                })
        }
    }

    val getData2 = StatefulMutableLiveData<YeBean>()
    fun getData2(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<YeBean>("/api/wallet/get_wallet_setting", *params,
                onStart = {
                    getData2.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData2.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData2.value = StateData.Success(it)
                })
        }
    }
}